home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Include / FWMaping.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.9 KB  |  313 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMaping.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMAPING_H
  11. #define FWMAPING_H
  12.  
  13. #ifndef FWGRDEF_H
  14. #include "FWGrDef.h"
  15. #endif
  16.  
  17. #ifndef FWPOINT_H
  18. #include "FWPoint.h"
  19. #endif
  20.  
  21. #ifndef FWRECT_H
  22. #include "FWRect.h"
  23. #endif
  24.  
  25. // ----- Foundation Includes -----
  26.  
  27. #ifndef FWEXCLIB_H
  28. #include "FWExcLib.h"
  29. #endif
  30.  
  31. #if FW_LIB_EXPORT_PRAGMAS
  32. #pragma lib_export on
  33. #endif
  34.  
  35. //========================================================================================
  36. //    Forward Class Declarations
  37. //========================================================================================
  38.  
  39. class FW_CLASS_ATTR ODShape;
  40. class FW_CLASS_ATTR ODTransform;
  41. class FW_CLASS_ATTR FW_CGraphicDevice;
  42.  
  43. //========================================================================================
  44. //    defines
  45. //========================================================================================
  46.  
  47. enum FW_EMappingModes
  48. {
  49.     FW_kCentimeter,
  50.     FW_kInch,
  51.     FW_kPoint,
  52.     FW_kDevice,
  53.     FW_kCustomConstrained,
  54.     FW_kCustomUnconstrained
  55. };
  56.  
  57. //========================================================================================
  58. //    class FW_CMapping
  59. //========================================================================================
  60.  
  61. class FW_CLASS_ATTR FW_CMapping FW_AUTO_DESTRUCT_OBJECT
  62. {
  63.  
  64. //----------------------------------------------------------------------------------------
  65. //    Constructors/Destructors
  66. //
  67. public:
  68.     FW_CMapping();
  69.     FW_CMapping(FW_EMappingModes mappingMode);
  70.     FW_CMapping(const FW_CMapping& mapping);
  71.  
  72.     virtual ~FW_CMapping();
  73.     
  74. //----------------------------------------------------------------------------------------
  75. //    operators
  76. //
  77. public:
  78.     FW_CMapping&    operator= (const FW_CMapping& mapping);
  79.     FW_Boolean        operator==(const FW_CMapping& mapping) const;
  80.     FW_Boolean        operator!=(const FW_CMapping& mapping) const;
  81.     
  82. //----------------------------------------------------------------------------------------
  83. //    New API
  84. //
  85. public:
  86.     
  87.     // ----- Setting the mapping -----
  88.  
  89.     void        Reset(Environment* ev);                    // Reset to default values;
  90.     
  91.     void        SetMappingMode(Environment* ev, FW_EMappingModes newMappingMode);
  92.     void        SetExtents(Environment* ev,
  93.                             const FW_CPoint& logicalExtent,
  94.                             const FW_CPoint& deviceExtent);
  95.     
  96.     FW_CPoint    GetLogicalExtent() const
  97.                     {return fLogicalExtent;}
  98.                     
  99.     FW_CPoint    GetDeviceExtent() const
  100.                     {return fDeviceExtent;}
  101.     
  102.     void        SetDeviceOrigin(Environment* ev, FW_CFixed x, FW_CFixed y);        // in device units (pixels)
  103.     void        SetLogicalOrigin(Environment* ev, FW_CFixed x, FW_CFixed y);        // in logical units
  104.     
  105.     FW_CPoint    GetDeviceOrigin() const
  106.                     {return fDeviceOrg;}
  107.                     
  108.     FW_CPoint    GetLogicalOrigin() const
  109.                     {return fLogicalOrg;}
  110.                     
  111.     // ----- Transform info -----
  112.  
  113.     FW_SPlatformPoint        GetOriginOffset(
  114.                                 Environment* ev,
  115.                                 FW_CGraphicDevice* device,
  116.                                 ODTransform* transform) const;
  117.  
  118. //----------------------------------------------------------------------------------------
  119. // Conversion
  120. //
  121. public:
  122.  
  123.     // ----- Logical ---> Content
  124.  
  125.     void                LogicalToContent(
  126.                             Environment* ev,
  127.                             const FW_CPoint& ptFrom,
  128.                             FW_CPoint& ptTo,
  129.                             FW_CGraphicDevice* device,
  130.                             ODTransform* transform = NULL) const;
  131.  
  132.     void                LogicalToContent(
  133.                             Environment* ev,
  134.                             const FW_CRect& rectFrom,
  135.                             FW_CRect& rectTo,
  136.                             FW_CGraphicDevice* device,
  137.                             ODTransform* transform = NULL) const;
  138.  
  139.     ODShape*            LogicalToContent(
  140.                             Environment* ev,
  141.                             ODShape* shape,
  142.                             FW_CGraphicDevice* device,
  143.                             ODTransform* transform = NULL) const;
  144.  
  145.     // ----- Logical ---> Device
  146.  
  147.     void                LogicalToDevice(
  148.                             Environment* ev,
  149.                             const FW_CPoint& ptFrom,
  150.                             FW_SPlatformPoint& ptTo,
  151.                             FW_CGraphicDevice* device,
  152.                             ODTransform* transform = NULL) const;
  153.  
  154.     void                LogicalToDevice(
  155.                             Environment* ev,
  156.                             const FW_CRect& rectFrom,
  157.                             FW_SPlatformRect& rectTo,
  158.                             FW_CGraphicDevice* device,
  159.                             ODTransform* transform = NULL) const;
  160.  
  161.     ODShape*            LogicalToDevice(
  162.                             Environment* ev,
  163.                             ODShape* shape,
  164.                             FW_CGraphicDevice* device,
  165.                             ODTransform* transform = NULL) const;
  166.  
  167.     // ----- Device ---> Logical
  168.  
  169.     void                DeviceToLogical(
  170.                             Environment* ev,
  171.                             const FW_SPlatformPoint& ptFrom,
  172.                             FW_CPoint& ptTo,
  173.                             FW_CGraphicDevice* device,
  174.                             ODTransform* transform = NULL) const;
  175.  
  176.     void                DeviceToLogical(
  177.                             Environment* ev,
  178.                             const FW_SPlatformRect& rectFrom,
  179.                             FW_CRect& rectTo,
  180.                             FW_CGraphicDevice* device,
  181.                             ODTransform* transform = NULL) const;
  182.  
  183.     ODShape*            DeviceToLogical(
  184.                             Environment* ev,
  185.                             ODShape* shape,
  186.                             FW_CGraphicDevice* device,
  187.                             ODTransform* transform = NULL) const;
  188.  
  189.     // ----- Device ---> Content
  190.  
  191.     void                DeviceToContent(
  192.                             Environment* ev,
  193.                             const FW_SPlatformPoint& ptFrom,
  194.                             FW_CPoint& ptTo,
  195.                             FW_CGraphicDevice* device,
  196.                             ODTransform* transform = NULL) const;
  197.  
  198.     void                DeviceToContent(
  199.                             Environment* ev,
  200.                             const FW_SPlatformRect& rectFrom,
  201.                             FW_CRect& rectTo,
  202.                             FW_CGraphicDevice* device,
  203.                             ODTransform* transform = NULL) const;
  204.  
  205.     ODShape*            DeviceToContent(
  206.                             Environment* ev,
  207.                             ODShape* shape,
  208.                             FW_CGraphicDevice* device,
  209.                             ODTransform* transform = NULL) const;
  210.  
  211.     // ----- Content ---> Logical
  212.                             
  213.     void                ContentToLogical(
  214.                             Environment* ev,
  215.                             const FW_CPoint& ptFrom,
  216.                             FW_CPoint& ptTo,
  217.                             FW_CGraphicDevice* device,
  218.                             ODTransform* transform = NULL) const;
  219.  
  220.     void                ContentToLogical(
  221.                             Environment* ev,
  222.                             const FW_CRect& rectFrom,
  223.                             FW_CRect& rectTo,
  224.                             FW_CGraphicDevice* device,
  225.                             ODTransform* transform = NULL) const;
  226.  
  227.     ODShape*            ContentToLogical(
  228.                             Environment* ev,
  229.                             ODShape* shape,
  230.                             FW_CGraphicDevice* device,
  231.                             ODTransform* transform = NULL) const;
  232.  
  233.     // ----- Content ---> Device
  234.  
  235.     void                ContentToDevice(
  236.                             Environment* ev,
  237.                             const FW_CPoint& ptFrom,
  238.                             FW_SPlatformPoint& ptTo,
  239.                             FW_CGraphicDevice* device,
  240.                             ODTransform* transform = NULL) const;
  241.  
  242.     void                ContentToDevice(
  243.                             Environment* ev,
  244.                             const FW_CRect& rectFrom,
  245.                             FW_SPlatformRect& rectTo,
  246.                             FW_CGraphicDevice* device,
  247.                             ODTransform* transform = NULL) const;
  248.  
  249.     ODShape*            ContentToDevice(
  250.                             Environment* ev,
  251.                             ODShape* shape,
  252.                             FW_CGraphicDevice* device,
  253.                             ODTransform* transform = NULL) const;
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    Implementation
  257. //
  258. protected:
  259.     void                ClearCache(Environment* ev);
  260.  
  261.     void                CheckCache(
  262.                             Environment* ev,
  263.                             FW_CGraphicDevice* device,
  264.                             ODTransform* transform) const;
  265.  
  266.     void                CalcCache(
  267.                             Environment* ev,
  268.                             FW_CGraphicDevice* device,
  269.                             ODTransform* transform);
  270.  
  271.     void                CalcOriginOffset(
  272.                             Environment* ev,
  273.                             FW_CGraphicDevice* device);
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    Data Members
  277. //
  278. public:
  279.     FW_EMappingModes        fMappingMode;
  280.     
  281.     FW_CPoint                fLogicalExtent;
  282.     FW_CPoint                fDeviceExtent;        
  283.  
  284.     FW_CPoint                fDeviceOrg;
  285.     FW_CPoint                fLogicalOrg;
  286.     
  287.     FW_SPlatformPoint        fOriginOffset;
  288.  
  289.     // ----- Cache -----
  290.     FW_CGraphicDevice*        fRecentDevice;
  291.     ODTransform*            fRecentODTransform;
  292.     
  293.     FW_Boolean                fHaveTransforms;
  294.  
  295.     ODTransform*            fLogicalToContentTransform;
  296.     ODTransform*            fContentToDeviceTransform;
  297.     ODTransform*            fLogicalToDeviceTransform;
  298. };
  299.  
  300. //----------------------------------------------------------------------------------------
  301. //    FW_CMapping::operator!=
  302. //----------------------------------------------------------------------------------------
  303. inline FW_Boolean FW_CMapping::operator!=(const FW_CMapping& mapping) const
  304. {
  305.     return !(*this == mapping);
  306. }
  307.  
  308. #if FW_LIB_EXPORT_PRAGMAS
  309. #pragma lib_export off
  310. #endif
  311.  
  312. #endif
  313.